package genericdemo;

/**
 * T:占位符
 * @param <T>
 */
class MyArray<T> {
    // public Object[] array = new Object[10];
    public T[] array = (T[])new Object[10];

    public T getPos(int pos) {
        return array[pos];
    }

    public void setPos(int pos, T val) {
        array[pos] = val;
    }

    public T[] getArray() {
        return array;
    }

}

public class TestDemo {

    public static void main(String[] args) {

        MyArray<Integer> myArray = new MyArray<Integer>();
        myArray.setPos(0, 1);
        //myArray.setPos(1, "hello");
        myArray.setPos(1, 2);
        Integer ret = myArray.getPos(1);

        //Integer[] s = myArray.getArray();
        System.out.println(ret);

    }
}
